from pydantic import BaseModel, Field
from typing import List, Optional
from datetime import datetime

class CompileOptions(BaseModel):
    """编译选项模型"""
    optimize: int = Field(2, ge=0, le=3, description="优化级别 0-3")
    python_version: str = Field("3", pattern="^[23]$", description="Python版本 2或3")
    platform: str = Field("linux", pattern="^(linux|windows|macos)$", description="目标平台")
    keep_source: bool = Field(False, description="是否保留源文件")
    zip_output: bool = Field(False, description="是否压缩输出")
    delete_temp: bool = Field(True, description="是否删除临时文件")
    extra_args: Optional[str] = Field(None, description="额外编译参数")
    output_dir: Optional[str] = Field(None, description="输出目录")

class FileInfo(BaseModel):
    """文件信息模型"""
    filename: str
    filesize: int

class CompileRequest(BaseModel):
    """编译请求模型"""
    options: CompileOptions
    files: List[FileInfo] = Field(..., min_items=1, description="要编译的文件列表")

class CompileResponse(BaseModel):
    """编译响应模型"""
    task_id: str
    status: str
    message: str

class CompileStatusResponse(BaseModel):
    """编译状态响应模型"""
    task_id: str
    status: str
    progress: int
    log: str
    completed_at: Optional[datetime] = None
    error_message: Optional[str] = None

class CompileResultResponse(BaseModel):
    """编译结果响应模型"""
    task_id: str
    status: str
    output_files: List[FileInfo]
    completed_at: datetime
